*****************************************************************
* Replication directory for                                   ***
* Prime locations                                             ***
* by Gabriel M. Ahlfeldt, Thilo N.H. Albers, Kristian Behrens ***
* Published in American Economic Review: Insights             ***
*****************************************************************
* 01/2025
* Stata
version 17.0

* This data set uses the data on prime location geography and accessibility mearures 
* to document the effect of polycentricity on accessibility
	
* Prepare data	
	u  "$temp/US-CBSAs/p${SL}/MSA_UsingData.dta", clear
	merge 1:1 cbsafp using "$temp/GISUS_using/MSApop20kmPL" // PL accessibility
	drop _m	
	merge 1:1 cbsafp using "$temp/GISUS_using/MSAttav" 		// PL travel times
	drop _m
	
* Run analysis
	gen lhpi = ln(hpi)
	label var lhpi "Ln house price index"
	gen lMSApopshare20kmPL = ln(MSApopshare20kmPL)
	label var lMSApopshare20kmPL "Ln PL accessibility"
	gen lMSA_tt_average = ln(MSA_tt_average)
	label var lMSA_tt_average "Ln commuting time"

	eststo:  reg lhpi  lmetro_emp PL_count, robust
	eststo:  reg lhpi  lmetro_emp PL_emp_pct, robust

	eststo:  reg lMSApopshare20kmPL  lmetro_emp PL_count , robust
	eststo:  reg lMSApopshare20kmPL  lmetro_emp PL_emp_pct , robust

	eststo:  reg lMSA_tt_average  lmetro_emp PL_count , robust
	eststo:  reg lMSA_tt_average  lmetro_emp PL_emp_pct , robust

* Write Appendix Table B.2.5
	capture mkdir "$tables_App/US-CBSAs"
	esttab  using "$tables_App/US-CBSAs/TAB_B2_5_PolycentricityEffects.tex", replace b(3) se(4) label compress   r2(3) ///
			stats( N r2 , fmt(%18.3g )   labels(  `"Observations"' `"\(R^{2}\)"' ))  ///   stats(Country_effects IV N r2) 0.* "`City'"
			title("Number of prime locations and congestion measures") modelwidth(6) nogap nostar  addnote( "Unit of observation is MSA." )	
			eststo clear	

* Script ends